define(["jquery","bbcare"],function($,$bb){
	var servers = {};
	var URL = $bb.baseUrl("followup");

	/**
     * 获取配置数据库时的参数 队列id
     */
    servers.getPageParams = function(){
        return $bb.getPageParams();
    }

	/* 请求患者 */
	servers.ajaxPatientsQueue = function(params,callback){
		$bb.ajax({
			url: URL + "followup/service/patient/patientQueueListQuery",
			data:JSON.stringify({	
				data : params
			}),
			success: function(data){
				if(data.success){
					callback(data.data,params);
				}else{
					$bb.toastShow(data.msg ? data.msg : "请求患者出错！");
				}	
			}
		});
	}

	/* 患者数据处理 */
	servers.babyListData = function(list,rows){
		var arr = [];
		for(var i=0;i<list.length;i++){
			arr[i] = list[i];
			arr[i].gender = list[i].gender;
			arr[i].percent = parseInt(list[i].completeNum / list[i].totalNum *100); 
			arr[i].width = 100 / list[i].totalNum + '%';
			if(list[i].taskStatusArr){	// 由于taskStatusArr字段是后加的，导致之前的数据会出错，所以在这里判断一下
				arr[i].taskStatusArr = JSON.parse(list[i].taskStatusArr);
				for (var j = 0; j < arr[i].taskStatusArr.length; j++) {
					if(arr[i].taskStatusArr[j] == '0'){
						arr[i].taskStatusArr[j] = "progress-notstart";
					}else if(arr[i].taskStatusArr[j] == '1'){
						arr[i].taskStatusArr[j] = "progress-finish";
					}else if(arr[i].taskStatusArr[j] == '2'){
						arr[i].taskStatusArr[j] = "progress-overdue";
					}
				}
			}
			var hisNo = {};
			if(arr[i].hisNo1){
				hisNo = { hisNo : arr[i].hisNo1 };
			}else if(arr[i].hisNo2){
				hisNo = { hisNo : arr[i].hisNo2 };
			}else if(arr[i].hisNo3){
				hisNo = { hisNo : arr[i].hisNo3 };
			}
			arr[i] = $.extend(hisNo,arr[i]);
		}
		if( arr.length < rows && arr.length > 0 ){
			var remainNum = rows - arr.length;
			for (var i = 0; i < remainNum; i++) {
				arr.push({});
			}
		}
		return arr;
	}

	return servers;
});